package com.tiza.xiaoyoubao.ui.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.tianze.library.base.BaseFragment;
import com.tiza.xiaoyoubao.R;
import com.tiza.xiaoyoubao.app.UIHelper;
import com.tiza.xiaoyoubao.entity.AdvancesCompleteInfo;
import com.tiza.xiaoyoubao.entity.MpMLSTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.TaskOperateInfo;
import com.tiza.xiaoyoubao.entity.TaskOrderInfo;
import com.tiza.xiaoyoubao.entity.TaskRebatesInfo;
import com.tiza.xiaoyoubao.entity.TaskShipMentsInfo;
import com.tiza.xiaoyoubao.utils.DateUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mapple on 17/5/22.
 * 手机美丽说任务2
 */

public class MpMLSTask2Fragment extends BaseFragment {

    @BindView(R.id.iv_goRight)
    ImageView iv_goRight;
    //商户ID
    @BindView(R.id.tv_sellerId)
    TextView tv_sellerId;
    //类型
    @BindView(R.id.tv_backType)
    TextView tv_backType;
    //价格
    @BindView(R.id.tv_cJPrice)
    TextView tv_cJPrice;
    //数量
    @BindView(R.id.tv_num)
    TextView tv_num;
    //任务状态
    @BindView(R.id.tv_taskState)
    TextView tv_taskState;
    //商家要求
    @BindView(R.id.tv_sellerRequire)
    TextView tv_sellerRequire;
    //订单留言
    @BindView(R.id.tv_message)
    TextView tv_message;
    //时间
    @BindView(R.id.tv_time)
    TextView tv_time;
    //任务编号
    @BindView(R.id.tv_taskId)
    TextView tv_taskId;
    //买号
    @BindView(R.id.tv_buyerId)
    TextView tv_buyerId;
    //商品金额
    @BindView(R.id.tv_price)
    TextView tv_price;
    //获得佣金
    @BindView(R.id.tv_getCommission)
    TextView tv_getCommission;
    //订单付款状态
    @BindView(R.id.tv_state)
    TextView tv_state;
    //商家确认订单状态
    @BindView(R.id.tv_sellerState)
    TextView tv_sellerState;
    //收货好评状态
    @BindView(R.id.tv_evaluationState)
    TextView tv_evaluationState;
    //任务完成状态
    @BindView(R.id.tv_taskCompleteState)
    TextView tv_taskCompleteState;
    @BindView(R.id.view1)
    View view1;
    @BindView(R.id.view2)
    View view2;
    @BindView(R.id.view3)
    View view3;
    @BindView(R.id.view4)
    View view4;
    private AdvancesCompleteInfo advancesCompleteInfo;
    private TaskOperateInfo taskOperateInfo;
    private TaskRebatesInfo taskRebatesInfo;
    private TaskShipMentsInfo taskShipMentsInfo;
    private MpMLSTaskOrderInfo mpMLSTaskOrderInfo;
    Bundle args;
    private String state;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        args = getArguments();
        state = args.getString("state");
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mp_mls_task2;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        switch (state) {
            case "AdvancesComplate":
                AdvancesComplate();
                break;
            case "operate":
                Operate();
                break;
            case "rebates":
                Rebates();
                break;
            case "shipments":
                Shipments();
                break;
            case "orderTask":
                OrderTask();
                break;
            default:
                break;
        }
    }


    @OnClick({R.id.view_go})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.view_go:
                UIHelper.showMpMLSTaskDetail2(mActivity,args);
                break;
            default:
                break;
        }
    }
    public void AdvancesComplate() {
        advancesCompleteInfo = (AdvancesCompleteInfo) args.getSerializable("info");
        tv_sellerId.setText("商家ID:" + advancesCompleteInfo.getUserId());
        tv_backType.setText(advancesCompleteInfo.getBackName());
        tv_cJPrice.setText(advancesCompleteInfo.getMobilePrice());
        tv_num.setText(advancesCompleteInfo.getNumber() + "件");
        tv_taskState.setText("任务状态：已完成");
        tv_state.setText("已完成");
        tv_sellerState.setText("已完成");
        tv_evaluationState.setText("已完成");
        tv_taskCompleteState.setText("已完成");
        if (advancesCompleteInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + advancesCompleteInfo.getRemarks());
        }
        if (TextUtils.isEmpty(advancesCompleteInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + advancesCompleteInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(advancesCompleteInfo.getBaseCmi()));
        view2.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        view3.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        view4.setBackgroundColor(getResources().getColor(R.color.steel_blue));
    }

    /**
     * 待操作
     */
    public void Operate() {
        taskOperateInfo = (TaskOperateInfo) args.getSerializable("info");
        tv_sellerId.setText("商家ID:" + taskOperateInfo.getUserId());
        tv_backType.setText(taskOperateInfo.getBackName());
        tv_cJPrice.setText(taskOperateInfo.getMobilePrice());
        tv_num.setText(taskOperateInfo.getNumber() + "件");
        tv_taskState.setText("任务状态：待操作");
        tv_state.setText("未完成");
        tv_sellerState.setText("未完成");
        tv_evaluationState.setText("未完成");
        tv_taskCompleteState.setText("未完成");
        if (taskOperateInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + taskOperateInfo.getRemarks());
        }
        if (TextUtils.isEmpty(taskOperateInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + taskOperateInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(taskOperateInfo.getBaseCmi()));
    }
    /**
     * 待操作(订单任务)
     */
    public void OrderTask() {
        mpMLSTaskOrderInfo = (MpMLSTaskOrderInfo) args.getSerializable("info");
        tv_sellerId.setText("商家ID:" + mpMLSTaskOrderInfo.getUserId());
        tv_backType.setText(mpMLSTaskOrderInfo.getBackName());
        tv_cJPrice.setText(mpMLSTaskOrderInfo.getMobilePrice());
        tv_num.setText(mpMLSTaskOrderInfo.getNumber() + "件");
        tv_taskState.setText("任务状态：待操作");
        tv_state.setText("未完成");
        tv_sellerState.setText("未完成");
        tv_evaluationState.setText("未完成");
        tv_taskCompleteState.setText("未完成");
        if (mpMLSTaskOrderInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + mpMLSTaskOrderInfo.getRemarks());
        }
        if (TextUtils.isEmpty(mpMLSTaskOrderInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + mpMLSTaskOrderInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(mpMLSTaskOrderInfo.getBaseCmi()));
    }
    /**
     * 待返款
     */
    public void Rebates() {
        taskRebatesInfo = (TaskRebatesInfo) args.getSerializable("info");
        tv_sellerId.setText("商家ID:" + taskRebatesInfo.getUserId());
        tv_backType.setText(taskRebatesInfo.getBackName());
        tv_cJPrice.setText(taskRebatesInfo.getMobilePrice());
        tv_num.setText(taskRebatesInfo.getNumber() + "件");
        tv_taskState.setText("任务状态：待返款");
        tv_state.setText("已完成");
        tv_sellerState.setText("未完成");
        tv_evaluationState.setText("未完成");
        tv_taskCompleteState.setText("未完成");
        if (taskRebatesInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + taskRebatesInfo.getRemarks());
        }
        if (TextUtils.isEmpty(taskRebatesInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + taskRebatesInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(taskRebatesInfo.getBaseCmi()));
        view2.setBackgroundColor(getResources().getColor(R.color.steel_blue));
    }

    /**
     * 发货中
     */
    public void Shipments() {
        taskShipMentsInfo = (TaskShipMentsInfo) args.getSerializable("info");
        tv_sellerId.setText("商家ID:" + taskShipMentsInfo.getUserId());
        tv_backType.setText(taskShipMentsInfo.getBackName());
        tv_cJPrice.setText(taskShipMentsInfo.getMobilePrice());
        tv_num.setText(taskShipMentsInfo.getNumber() + "件");
        tv_taskState.setText("任务状态：待评价");
        tv_state.setText("已完成");
        tv_sellerState.setText("已完成");
        tv_evaluationState.setText("未完成");
        tv_taskCompleteState.setText("未完成");
        if (taskShipMentsInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + taskShipMentsInfo.getRemarks());
        }
        if (TextUtils.isEmpty(taskShipMentsInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + taskShipMentsInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(taskShipMentsInfo.getBaseCmi()));
        view2.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        view3.setBackgroundColor(getResources().getColor(R.color.steel_blue));
    }

}
